<template>
  <div class="fenlie_book_center">
    <div class="fenlei_box">
      <div>
        图书名称:
        <el-input
          placeholder="请输入图书名称关键字"
          v-model.lazy="query.bookname"
          clearable
        >
        </el-input>
      </div>
      <div>
        图书分类:
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="西游记" value="1"></el-option>
          <el-option label="流浪地球" value="2"></el-option>
          <el-option label="金刚大战特斯拉" value="3"></el-option>
          <el-option label="哪吒之魔童降世" value="4"></el-option>
          <el-option label="哪吒之浴火重生" value="5"></el-option>
        </el-select>
      </div>
      <div>
        作者:
        <el-input
          placeholder="请输入内容"
          v-model.lazy="query.zuozhe"
          clearable
        ></el-input>
      </div>

      <div>
        出版社:
        <el-input
          placeholder="请输入内容"
          v-model.lazy="query.chuban"
          clearable
        >
        </el-input>
      </div>
    </div>
    <div class="fenlei_box1">
      <div>
        出版时间:
        <el-date-picker v-model="date" type="date" placeholder="选择日期">
        </el-date-picker>
      </div>

      <div>
        入库人:
        <el-input
          placeholder="请输入姓名"
          v-model.lazy="query.ren"
          clearable
        ></el-input>
      </div>
      <div>
        入库时间:
        <el-date-picker v-model="date2" type="date" placeholder="选择日期">
        </el-date-picker>
      </div>
      <el-button type="primary" @click="onClickseach">
        <i class="el-icon-search"></i>
        搜索</el-button
      >
      <el-button type="primary" @click="onClickchong">
        <i class="el-icon-refresh-left"></i>
        重置</el-button
      >
    </div>
    <el-button type="primary">新增图书</el-button>

    <el-table :data="books" border style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="id" label="图书ID" width="65"> </el-table-column>
      <el-table-column label="图书名称" width="170">
        <template slot-scope="scope">
          <div class="dis_felx">
            <img :src="scope.row.cover_img" alt="" />
            <p>{{ scope.row.name }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="book_classify" label="所属分类" width="100">
      </el-table-column>
      <el-table-column prop="author" label="作者" width="100">
      </el-table-column>
      <el-table-column prop="price" label="价格" width="120"> </el-table-column>
      <el-table-column prop="stock" label="库存" width="120"> </el-table-column>
      <el-table-column prop="publisher" label="出版社" width="120">
      </el-table-column>
      <el-table-column label="出版时间" width="180">
        <template slot-scope="scope">
          {{ scope.row.created_at | formatDate }}
        </template>
      </el-table-column>
      <el-table-column label="状态" width="120">
        <template slot-scope="scope">
          {{ scope.row.status === 1 ? "启用" : "禁用" }}
        </template>
      </el-table-column>
      <el-table-column prop="creator_id" label="序号" width="120">
      </el-table-column>
      <el-table-column prop="creator" label="入库人" width="120">
      </el-table-column>
      <el-table-column prop="publish_time" label="入库时间" width="180">
        <template slot-scope="scope">
          {{ scope.row.created_at | formatDate }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="180">
        <template>
          <el-link size="mini">排序</el-link>-
          <el-link size="mini">编辑</el-link>-
          <el-link size="mini">下架</el-link>-
          <el-link size="mini">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <div class="left_right">
      <el-link :disabled="true">上架 下架 删除</el-link>
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="pageClicked"
        :current-page="query.page"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="query.limit"
        layout="total, prev, pager, next, jumper, sizes"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getbooks } from '../../api/api5'
export default {
  data() {
    return {
      total: 0,
      select: '',
      book: '',
      date2: '',
      zuozhe: '',
      input: '',
      chuban: '',
      date2: '',
      date: '',
      ren: '',
      books: [],
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      list: [],
      copybooks: [],
      query: {
        page: 1,
        limit: 4,
        bookname: '',
        zuozhe: '',
        chuban: '',
        ren: ''
      }
    }
  },
  methods: {
    onClickchong() {
      this.query.bookname = ''
      this.onClickseach()
    },
    pageSizeChange(size) {
      // 更新本地每页条数
      this.query.limit = size
    },
    pageClicked(page) {
      // 更新翻页变量
      this.query.page = page
    },
    onClickseach() {
      console.log(111)
      this.books = this.copybooks.filter((item) => {
        console.log(item)
        return (
          item.name.includes(this.query.bookname) &&
          item.author.includes(this.query.zuozhe) &&
          item.publisher.includes(this.query.chuban) &&
          item.creator.includes(this.query.ren)
        )
      })
    },
    getlist() {
      getbooks(this.query).then((res) => {
        console.log(res)
        this.books = res.data.list
        this.copybooks = res.data.list
        this.total = res.data.total
      })
    }
  },
  watch: {
    query: {
      deep: true,
      handler() {
        console.log(111)
        this.getlist()
      }
    }
  },
  created() {
    this.getlist()
  }
}
</script>

<style lang="scss">
* {
  padding: 0;
  margin: 0;
}
.fenlei_box {
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  div {
    width: 75%;
  }
}
.fenlei_box1 {
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  div {
    width: 70%;
  }
}
.cell {
  text-align: center;
}
.is-leaf {
  text-align: center !important;
}
.el-table__row {
  height: 50px !important;
}
.left_right {
  .el-link {
    font-size: 13px;
  }
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dis_felx {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
img {
  width: 50px;
  height: 50px;
}
</style>
